<cfif Not IsDefined("session.id")>
		<cflocation url = "/ecada/" addToken = "no">
</cfif>
	
<cfif IsDefined("session.experiment")>
	<cfset experiment = session.experiment>
<cfelse>
	<cflocation url="/ecada/">
</cfif>

<cfif IsDefined("form.submit")>
	<cfset folderUID = CreateUUID()>
	
	<cfdirectory action = "create" directory = "#ExpandPath('/ecada/files/' & folderUID)#" mode = 777 >
	
	<cffile action="UPLOAD" 
		destination="#ExpandPath('/ecada/files/' & folderUID)#" 
		nameconflict="MAKEUNIQUE" 
		filefield="ImageFile"
		result="ImageDetails">
		
	<cfquery datasource="exp" result="filestore">
		INSERT INTO filestore (filename, filepath, fileext, mimetype)
		VALUES ('#ImageDetails.ServerFile#', '#folderUID#', '#ImageDetails.ServerFileExt#', '')
	</cfquery>
	<cfdump var="#filestore#">
	<cfquery datasource="exp" result="Stimuli">
		INSERT INTO stim (CondID, fileID, StimuliTypeID, Title, Description)
		VALUES ( #CondID#, #filestore.GENERATED_KEY#, (SELECT id FROM stimulitype WHERE type='picture'), '#Title#', '' )
	</cfquery>
	
	<cflocation url="./../" addToken="no">
<cfelse>
	<cfinclude template= "/ecada/header.cfm">
	<cfoutput>
		<form method="post" enctype="multipart/form-data" action="index.cfm">
			<fieldset>
				<legend>
					Stimuli Options
				</legend>
				<table>
					<tr>
						<td>
							Title
						</td>
						<td>
							<input type="Textbox" name="Title" id="Title">
						</td>
					</tr>
					<!---<tr>
						<td>
							Description
						</td>
						<td>
							<input type="Textbox" name="Description" id="Description">
						</td>
					</tr>--->
				</table>
			</fieldset>
			<fieldset>
				<legend>
					Stimuli Selection
				</legend>
				<p>
					You can select an image here to upload. The best formats for image are as follows:
					
						<ul>
							<li>PNG</li>
							<li>JPG/JPEG</li>
							<li>GIF</li>
						</ul>	
					BMP's are also acceptable, however they are usally very large in size and are not recomened. If you use BMP's please take note that they time they take to download to the participants computer will affect the timing results.
				</p>
				<input type="file" name="ImageFile" id="ImageFile">
			</fieldset>
			<input type="hidden" name="CondID" id="CondID" value="#HTMLEditFormat(condID)#">
			<input type="submit" value="Submit" name="submit" id="submit">
		</form>
	</cfoutput>
	<cfinclude template= "/ecada/footer.cfm">
</cfif>



